package com.session1;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;
public class Demolayout extends JFrame {
	private JLabel lblFName,lblLName;
	private JTextField txtFName,txtLName;
	private JPanel p1;
	public void createForm(){
		this.lblFName = new JLabel("Frist Name");
		this.lblLName = new JLabel("Last Name");
		this.txtFName = new JTextField(18);
		this.txtLName = new JTextField(18);
		
		//set layout cho JFrame
		p1 = new JPanel();
//		this.p1.setLayout()
		this.p1.add(lblFName);
		this.p1.add(txtFName);
		this.p1.add(lblLName);
		this.p1.add(txtLName);
		this.getContentPane().add(this.p1);
		this.p1.setPreferredSize(new Dimension(300,200));
		p1.setBorder(BorderFactory.createTitledBorder("Infomation"));
		this.setLayout(new FlowLayout(FlowLayout.LEFT));
	}
	public void createFormWithMiglayout(){
		this.setLayout(new MigLayout());
		this.getContentPane().add(new JButton("1"));
		this.getContentPane().add(new JButton("2"),"wrap");
		this.getContentPane().add(new JButton("3"));
		this.getContentPane().add(new JButton("4"),"wrap");
		this.getContentPane().add(new JButton("5"));
	}
	public  void showFrom() {
		this.setTitle("Demo Layout");
		this.setSize(400,300);
//		this.pack();
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	public void createFormWithBorderLayout(){
		
		//set Layout cho JFrame
		this.setLayout(new BorderLayout());
		this.getContentPane().add(new JButton("Button 1"), BorderLayout.SOUTH);
		
		JPanel p = new JPanel();
		p.setLayout(new FlowLayout(FlowLayout.RIGHT));
		p.add(new JButton("Buttion 1"));
		p.add(new JButton("Buttion 2"));
		p.add(new JButton("Buttion 3"));
		this.getContentPane().add(p, BorderLayout.SOUTH);
		
		this.getContentPane().add(new JLabel("Content"),BorderLayout.NORTH);
		this.getContentPane().add(new JTextArea(),BorderLayout.CENTER);
	}
	public void createFormWithGridLayout(){
		this.setLayout(new BorderLayout());
		this.getContentPane().add(new JTextField(), BorderLayout.NORTH);
		
		JPanel p = new JPanel();
		p.setLayout(new GridLayout(3,3,5,5));
		p.add(new JButton("1"));
		p.add(new JButton("2"));
		p.add(new JButton("3"));
		p.add(new JButton("4"));
		p.add(new JButton("5"));
		p.add(new JButton("6"));
		this.getContentPane().add(p,BorderLayout.CENTER);
	}
	public static void main(String[] args) {
		Demolayout d = new Demolayout();
//		d.createForm();
//		d.createFormWithBorderLayout();
//		d.createFormWithGridLayout();
		d.createFormWithMiglayout();
		d.showFrom();
	}
}